package cwinsor.raking.year2014;

public class PropertyPhysicalInteger extends PropertyPhysical {

	public void setPropertyValFromString(String string) {
		Integer integer = null;

		// sanity check - look for a null string input
		if (string.equals(null)) {
			Msg.fatal(dM + ":hold everything - you are trying to set Integer property where the string text is null!");
		}

		// if the string has "" then provide "0" as the default
		if (string.equals("")) {
			string = "0";
		}

		// sanity check - confirm the string can be converted to an integer
		try {
			integer = new Integer(string);
		} catch (NumberFormatException e) {
			Msg.fatal(dM + ": when setting property value from string - cannot convert \"" + string + "\" to an Integer");
		}

		// set the base class Object
		object = integer;
	}

	public PropertyBase prototype() {
		PropertyBase prototype = new PropertyPhysicalInteger();
		return prototype;
	}

	public Object getValue() {
		return toInteger();
	}

	public Integer toInteger() {
		Integer temp = (Integer)object;
		return temp;
	}

	public String toString() {
		Integer temp = (Integer)object;
		if (temp.equals(0))
			return "";
		String tempS = temp.toString();
		return tempS;
	}

	public int compareTo(PropertyBase arg0) {
		return toInteger() - arg0.toInteger();
	}
	
	// debug
	String dM = this.getClass().getSimpleName();
}
